package com.jia.thumps.controller;

import com.jia.thumps.service.FileService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author jia
 */
@RestController
@RequestMapping("/file")
// 上传相关的Controller类，包括图片上传、视频上传等功能
public class UploadController {

    @Resource
    private FileService fileService;

    @PostMapping("upload")
    public ResponseEntity<String> upload(@RequestParam("file") MultipartFile file) {
        return ResponseEntity.ok(fileService.uploadFile(file));
    }

    @PostMapping("merge")
    public ResponseEntity<String> merge(@RequestParam("fileId") String fileId) {
        return ResponseEntity.ok(fileService.mergeFile(fileId));
    }


    @GetMapping("download")
    public ResponseEntity<String> download(@RequestParam("fileId") String fileId, HttpServletRequest request, HttpServletResponse response) {
        return ResponseEntity.ok(fileService.downloadFile(fileId, request, response));
    }

}
